草庐IT

PHP filter_input 验证 INT

全部标签

go - 求一个 big.Int 的平方根

我的项目需要使用big.Ints,因为我使用的数字超过了int64限制。对于常规整数,您可以使用以下方法对其求平方:math.Sqrt(value)但我不知道如何做到这一点,但使用big.Ints。任何帮助将不胜感激,谢谢 最佳答案 使用https://golang.org/pkg/math/big/#Int.Sqrtbig.int接口(interface)给出packagemainimport("fmt""math/big")funcmain(){varStr=`1000000000000000000000000000000000

http - 禁用公用名验证 - Go HTTP 客户端

如何在gohttp客户端中禁用通用名称验证。我正在使用通用CA执行双向TLS,因此通用名称验证没有任何意义。TLSdocs说,//ServerNameisusedtoverifythehostnameonthereturned//certificatesunlessInsecureSkipVerifyisgiven.Itisalsoincluded//intheclient'shandshaketosupportvirtualhostingunlessitis//anIPaddress.ServerNamestring我不想执行InsecureSkipVerify但我不想验证通用名称。

go - CRAM-MD5 身份验证期间的不同哈希值

作为练习,我正在尝试在Go中实现一个带有CRAM-MD5身份验证的模拟SMTP服务器(不遵循RFC2195,因为对于客户端来说,预哈希挑战是什么格式似乎无关紧要in;我还假设只有一个用户“bob”,密码为“pass”)。但我似乎无法正确处理,因为响应中的哈希总是与我在服务器上拥有的不同。我使用Go发送电子邮件(将其作为单独的包运行):{...}smtp.SendMail("localhost:25",smtp.CRAMMD5Auth("bob","pass"),"bob@localhost",[]string{"alice@localhost"},[]byte("HeyAlice!\n

json - 使用数组中包含的 [int] 字符串映射解码 JSON

我试图将以下JSON解码为一个结构,但我无法用[[int,string]]翻译值字段的内容这是我到目前为止所拥有的:typeResponsestruct{Metricstruct{Namestring`json:"name,omitempty"`Appnamestring`json:"appname,omitempty"`}`json:"metric,omitempty"`Values[]map[int]string`json:"values,omitempty"`}JSON文件:{"metric":{"name":"x444","appname":"cc-14-471s6"},"va

multithreading - Go 服务器在发送 INT 信号后挂起

代码如下:packagemainimport("log"_"net/http/pprof""fmt""net/http""html""os/signal""os")funcmain(){//INTsignalhandlingc:=make(chanos.Signal,1)signal.Notify(c,os.Interrupt)gofunc(){forrangec{log.Println("GOTSIGNAL!")return}}()//INTsignalhandlinghttp.HandleFunc("/bar",func(whttp.ResponseWriter,r*http.Re

json - 使用 Avro Schema 验证 Json 文件

我正在尝试检查Json字符串是否与Avro架构匹配。我不关心数据的序列化,只关心isValidJson=true/false的bool结果。我将使用每个golang库。我试着用这个goavro写点东西lib,但它对我不起作用,可能是因为我是golang的新手。所需的伪代码:funcmain(){avroSchema:=`{"type":"record","name":"raw","namespace":"events","fields":[{"name":"my_int","type":["null","int"],"default":null},{"name":"my_string"

go - 如何验证来自appEngine灵活的可恢复上传,类似于golang中的SignedURL

我得到这个代码来获得一个signedURL:import("net/http""time""cloud.google.com/go/storage""google.golang.org/appengine")//Don´tworryabouttheerrors,I´mhandlingthemfuncCreatSignedURL(r*http.Request)(string,error){ctx:=appengine.NewContext(r)acc,_:=appengine.ServiceAccount(ctx)filename:="fileName"bucket:="bucketNa

go - 使用反射设置 nil *int32 结构字段

我正在尝试通过反射设置nil*int的值。在下面的示例中,replaceNilWithNegativeOne应该替换任何nil*int32字段(标记为grib:"foo")和一个指向-1的指针。但是,当代码运行时,reflect会出现panic,并显示panic:reflect:reflect.Value.Setusingunaddressablevalue。我在其他几个地方看到了几乎与我在这里问的完全相同的问题,例如:Usingreflect,howdoyousetthevalueofastructfield?Usingreflect,howdoyouinitializevalueo

go - 如何在 go 中实现碎片化的配置文件验证

我尝试通过配置文件(yaml)配置CLI应用程序。该应用程序有几个“组件”(比方说持久层、集成网络服务器等)。这些组件在子包中进行管理,以保持代码整洁。这些组件的配置在它们的包中定义并在配置包中“合并”到表示配置文件的结构。将此代码视为演示实现:packagemainimport("errors""fmt"yaml"gopkg.in/yaml.v2")////Thiswouldbeinpackage'webserver'//OnlytheConfigpartisshown,therewouldbeaconstructorandtheimplementationof//thewebser

json - Marshal/Unmarshal int 类型

我使用int类型来表示枚举。当我将它编码为JSON时,我想将它转换为字符串,据我所知,我应该实现UnmarshalJSON和MarshalJSON,但它提示:marshalerror:json:errorcallingMarshalJSONfortypemain.trxStatus:invalidcharacter'b'lookingforbeginningofvalueunexpectedendofJSONinput编码时。然后我将引号添加到编码字符串中:func(strxStatus)MarshalJSON()([]byte,error){return[]byte("\""+s.S